package com.baizhi.service.impl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.BannerDao;
import com.baizhi.service.BannerService;
import com.baizhi.entity.Banner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerDao bannerDao;
    @Override
    public Map insertBanner(Banner banner) {
        Map map=new HashMap();
        int count=bannerDao.insertBanner(banner);
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }

    @Override
    public Map deleteBannerById(int bannerId) {
        Map map=new HashMap();
        int count=bannerDao.deleteBannerById(bannerId);
        if(count>0){
            map.put("isDelete",true);
        }else{
            map.put("isDelete",false);
        }
        return map;
    }

    @Override
    public Map updateBanner(Banner banner) {
        Map map=new HashMap();
        int count=bannerDao.updateBanner(banner);
        if(count>0){
            map.put("isUpdate",true);
        }else{
            map.put("isUpdate",false);
        }
        return map;
    }

    @Override
    @LogAnnotation(value = "ddd",type = "ddd")
    public Map showAllBanner(int page, int limit) {
        Map map=new HashMap();
        int offset=(page-1)*limit;
        int count=bannerDao.selectCount();
        List<Banner> list=bannerDao.selectAllBanner(offset,limit);

        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @Override
    public Banner selectOne(int bannerId) {
       Banner banner=bannerDao.selectOne(bannerId);
        return banner;
    }
}
